home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Hooks.h
-
- Contains: Hooking into the Mac OS by intercepting traps
- Creating a Hook object automatically installs the
- hooks. Deleting a hook object automaticly disables
- the hooks, but if somebody else has patched one of the
- same traps in the mean-time, our hook is left in the
- system heap. This is a minor core leak, but much better
- than crashing the next time the trap is called.
-
- Written by: Jack Palevich, [Original idea and C implementation by Jay Fenton]
-
- Copyright: © 1989 by Apple Computer, Inc., all rights reserved.
-
- Change History:
-
- 10/15/89 JHP objectified today
-
- To Do:
- */
-
- #ifndef __HOOKS__
- #define __HOOKS__
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- struct hookentry;
-
- struct THookStackFrame
- {
- short trap;
- long d0;
- long d1;
- long d2;
- long d3;
- long d4;
- long d5;
- long d6;
- long d7;
- void* a0;
- void* a1;
- void* a2;
- void* a3;
- void* a4;
- void* a5;
- void* returnAddress;
- char argBase;
- };
-
- class THooks {
- public:
- THooks(short numTraps, const short* trapList,
- pascal void (*trapHandler)(short, THookStackFrame*, void* userRefNum),
- void* userRefNum);
- ~THooks();
- private:
- short fNumHooks;
- hookentry* fHooks;
- };
-
- // Useful for SetTrapAddress and GetTrapAddress
-
- inline void TrapToTypeAndNum(short trap, TrapType& trapType, short& trapNum)
- {
- trapType = ( trap >> 11 ) & 1;
- trapNum = trap & ( ( trapType ) ? 0x3ff : 0xff );
- }
-
- #endif